/*
 * Bulletin board server by Pedro Tabacof - ID 2101353
 * CSC414 - Computer Networks - Prof. Stefan Bruda
 * Bishop's University
 *
 * This is a simple bulletin board multi-threaded server.
 *
 * More information can be found in the README file or in the comments below.
 */

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <poll.h>
#include <sched.h>
#include <inttypes.h>

/* Binary search on the thread_pool.
 * Returns the place in the vector of requested thread ID.
 * Or -1 if not matching thread was found.
 */
int binary_search(pthread_t thread, pthread_t *thread_pool, int a, int b);

/* Removes thread from thread pool using binary search above.
 * Returns 0 if thread wasnt found, or the thread itself.
 */
pthread_t thread_pool_remove(pthread_t t, pthread_t *thread_pool, int n);

/* Insertion sort used to sort the thread_pool, so the binary search will work.
 * Since threads are inserted each one of a time, the vector is always sorted
 * so insertion sort will be always O(n).
 */
void insertion_sort(pthread_t v[], int n);

/* Inserts a thread into the thread_pool and uses insertion_sort to sort the result. */
void thread_pool_insert(pthread_t t, pthread_t *thread_pool, int n);

